package com.joplus.housekeeper.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.animation.AlphaAnimation;
import android.view.animation.Animation;
import android.view.animation.AnimationSet;
import android.view.animation.TranslateAnimation;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.joplus.housekeeper.R;
import com.joplus.housekeeper.bean.BagCustmizedInfo;
import com.joplus.housekeeper.utils.StringUtils;
import com.nostra13.universalimageloader.core.ImageLoader;

import java.util.List;

/**
 *
 *author： wutingxi
 *time： 2017/2/13 16:43
 *description：颜色选择适配器
 */
public class MaterialPickAdapter extends BaseAdapter {
    private Context mContext;

    private LayoutInflater mInflate;
    List<BagCustmizedInfo.DataBean.DictListBean> datas;

    public MaterialPickAdapter(Context context) {
        this.mContext = context;
    }


    public void setData(List<BagCustmizedInfo.DataBean.DictListBean> datas){
        this.datas=datas;
        notifyDataSetChanged();
    }
    @Override
    public int getCount() {
        if(datas!=null){
            return datas.size();
        }else{
            return 0;
        }

    }

    @Override
    public Object getItem(int position) {
        return null;
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {

        mInflate = LayoutInflater.from(mContext);


        convertView=mInflate.inflate(R.layout.item_material_pick,null,false);

        ViewHold viewHold=new ViewHold();
        viewHold.icon=(ImageView) convertView.findViewById(R.id.iv_icon);
        viewHold.name=(TextView) convertView.findViewById(R.id.tv_name);

        ImageLoader.getInstance().displayImage(datas.get(position).getValueContent(),viewHold.icon);
        StringUtils.setText(viewHold.name,datas.get(position).getName());
        AnimationSet animationSet=new AnimationSet(mContext,null);
        TranslateAnimation translate = new TranslateAnimation(Animation.RELATIVE_TO_SELF, -1f,
                Animation.RELATIVE_TO_SELF, 0.0f, Animation.RELATIVE_TO_SELF,
                -1.0f, Animation.RELATIVE_TO_SELF, 0.0f);
        translate.setDuration(500);//动画时间500毫秒
        translate.setFillAfter(true);//动画出来控件可以点击
        AlphaAnimation b=new AlphaAnimation(0f,1f);
        b.setDuration(800);
        animationSet.addAnimation(translate);
        animationSet.addAnimation(b);
        convertView.setAnimation(b);
        return convertView;
    }



    private  class ViewHold{
        public ImageView icon;
        public TextView name;
    }


}
